#include <GameEngine/Core/timer.h>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif

//=========================================================================================

//! Default constructor
/*!
 *  Create a timer and starts it
 */
Timer::Timer() : _clocks(0), _freq(0) {
	reset();
}

//! Destructor
Timer::~Timer() {}

//! Compute the time elapsed since the timer was created
/*!
 @return The time elapsed since the timer was created, or since the last
         call of the reset() function. Time is returned in seconds.
 */
Time::Seconds Timer::elapsed_time() const {
	__int64 clocks;
	QueryPerformanceCounter((LARGE_INTEGER *)&clocks);
	return ((Time::Seconds)(clocks-_clocks) / (Time::Seconds)_freq);
}

//! Reset the timer
/*!
 *  Function elapsed_time() will now measure time elapsed since this call
 *  of the reset() function
 */
void Timer::reset() {
	QueryPerformanceFrequency((LARGE_INTEGER *)&_freq);
	QueryPerformanceCounter((LARGE_INTEGER *)&_clocks);
}

//=========================================================================================

#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif
